/*
 *  Check Form Login
 */
function checkLogin(){
    if(document.login.user.value==""){
        alert("Vui lòng nhập UserName ");
        document.login.user.focus();
        return false;
    }
    if(document.login.pass.value=="" ){
        alert("Vui lòng nhập Password");
        document.login.pass.focus();
        return false;
    }
    return true;
}
function checkFeed()    {
    var tsmail=/^[a-zA-Z][\w\.]*@[a-zA-Z]{2,10}\.[a-zA-Z]{2,4}$/;
    var tsTel=/^\d{7,11}$/;

    var tit = document.feed.tit.value;
    var content = document.feed.content.value;
    var mail = document.feed.mail.value;
    var tel = document.feed.tel.value;

    if (tit == "")  {
        alert("Title can't null");
        document.feed.tit.focus();
        return false;
    }
    if (content == "")  {
        alert("Content can't null");
        document.feed.content.focus();
        return false;
    }
    if (mail == "") {
        alert("Mail can't null");
        document.feed.mail.focus();
        return false;
    }
    if (tsmail.test(mail) == false)  {
        alert("Mail format invaild");
        document.feed.mail.value = "";
        document.feed.mail.focus();
        return false;
    }
    if (tel == "") {
        alert("Tel can't null");
        document.feed.tel.focus();
        return false;
    }
    if (tsTel.test(tel) == false)  {
        alert("Tel format invaild");
        document.feed.tel.value = "";
        document.feed.tel.focus();
        return false;
    }
    return true;
}

function checkRegister(){

    var name = document.register.user.value;
    var pass = document.register.pass.value;
    var pass2 = document.register.pass2.value;
    var tsPass= /^\w+$/i;
    var mail = document.register.mail.value;
    var fName = document.register.fullname.value;
    var tsmail=/^[a-zA-Z][\w\.]*@[a-zA-Z]{2,10}\.[a-zA-Z]{2,4}$/;
    var tel = document.register.tel.value;
    var tsTel=/^\d{7,11}$/;
    var add = document.register.add.value;

    var messenger="";
    var temp=1;

    var object1 = 1;

    var dateStr = document.register.birthday.value;
    var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

    

    
    

    


    if (name == "")	{
        alert("UserName can't null");
        document.register.user.focus();
        return false;
    }
    var matchArray = dateStr.match(datePat); // is the format ok?
    day = matchArray[1];
    month = matchArray[3];
    year = matchArray[4];
    
    if (pass == "")	{
        alert("Password can't null");
        document.register.pass.focus();
        return false;
    }
    if (tsPass.test(pass) == false) {
        alert("Setup pass [a-z][0-9] !"+"required 6->16 character");
        document.register.pass.value = "";
        document.register.pass.focus();
        return false;
    }
    if (pass2 == "")	{
        alert("Password confirm is null");
        document.register.pass2.focus();
        return false;
    }
    if (pass != pass2)	{
        alert("Password confirm invaild");
        document.register.pass2.value = "";
        document.register.pass2.focus();
        return false;
    }
    if (mail == "")	{
        alert("Email is not null");
        document.register.mail.focus();
        return false;
    }
    if (tsmail.test(mail) == false) {
        alert("Email invaild format .ex : abcd@efdg.com");
        document.register.mail.value = "";
        document.register.mail.focus();
        return false;
    }
    if (fName == "")	{
        alert("Fullname can't null");
        document.register.mail.focus();
        return false;
    }

    //Begin check birthday
    if (matchArray == null) {
        // show error
        messenger = messenger + " - Date format invaild, please try again \n";
        temp = temp + 1;
        alert(messenger);
        return false;
    }
    if (day < 1 || day > 31) {
        // show error
        messenger = messenger + " - Day from 1-31 \n";
        temp = temp + 1;
        alert(messenger);
        return false;
    }

    if (month < 1 || month > 12) { // check month range
        // show error
        messenger = messenger + " - Month from 1-12 \n";
        temp = temp + 1;
        alert(messenger);
        return false;
    }
    if ((month==4 || month==6 || month==9 || month==11) && day==31) {
        // show error
        messenger = messenger + " - Moth " + month + "haven't 31 day \n";
        temp = temp + 1;
        alert(messenger);
        return false;
    }
    if (month == 2) { // check for february 29th
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day>29 || (day==29 && !isleap)) {
            // show error
            messenger = messenger + " - Moth 2 Year " + year + "haven't" + day +" <br>";
            temp = temp + 1;
            alert(messenger);
            return false;
        }
    }
    if(temp!=1){
        alert(messenger);
        return false;
    }

    //End check date


    if  (tel == "") {
        alert("Telephone can't null");
        document.register.tel.focus();
        return false;
    }
    if  (tsTel.test(tel) == false) {
        alert("Telephone format with number");
        document.register.tel.value = "";
        document.register.tel.focus();
        return false;
    }
    
    return true;
}
